/**
 * 
 */
package Test;


import java.util.Date;

import junit.framework.TestCase;

import org.junit.Before;
import org.junit.Test;

import business.Accounts;
import data.Job;
import data.Scheduler;
import data.Volunteer;

/**
 * This class performs basic unit testing functionality for the Scheduler class.
 * 
 * @author Stephen Amos
 * @version 1.0
 */
public class SchedulerTest extends TestCase {
	/**
	 * scheduler.
	 */
	private Scheduler test_scheduler;
	/**
	 * username.
	 */
	private String username;
	/**
	 * password.
	 */
	private String password;
	/**
	 * phone.
	 */
	private String phone;
	/**
	 * email.
	 */
	private String email;

	/**
	 * This method instantiates a Scheduler object, and populates it with
	 * a set of test field values. 
	 */
	@Before
	public void setUp() throws Exception {
		username = "username";
		password = "password";
		phone = "123-456-7890";
		email = "scheduler@email.com";
		test_scheduler = new Scheduler(username, password, phone, email);
	}
	
	/**
	 * This method tests a Scheduler object's constructor.
	 * 
	 * 1) Test whether the Scheduler object's firstname field has been created
	 * successfully with the correct data.
	 * 2) Test whether the Scheduler object's surname field has been created
	 * successfully with the correct data.
	 * 3) Test whether the Scheduler object's username field has been created
	 * successfully with the correct data.
	 * 4) Test whether the Scheduler object's password field has been created
	 * 
	 * All assertions in this method should return true.  If one or more
	 * assertion fails, the constructor has failed to create a Scheduler object
	 * as intended.
	 */
	@Test
	public void testScheduler() {
		String test_username = test_scheduler.getUsername();
		String test_password = test_scheduler.getPassword();
		String test_phone = test_scheduler.getPhone();
		String test_email = test_scheduler.getEmail();
		
		assertEquals("Username assertion failed.", test_username.equals(username), true);
		assertEquals("Password assertion failed.", test_password.equals(password), true);
		assertEquals("Phone assertion failed.", test_phone.equals(phone), true);
		assertEquals("Email assertion failed.", test_email.equals(email), true);
	}
	
	/**
	 * Tests whether the equals method for the Scheduler class functions
	 * as intended.
	 * 
	 * 1) This assertion passes if the objects are equal. 
	 * 
	 * All assertions in this method should return true.  If one or more
	 * assertion fails, the equals method has failed to function as intended
	 * for the Scheduler class.
	 */
	@Test
	public void testEquals() {
		String username = "username";
		String password = "password";
		String phone = "123-456-7890";
		String email = "scheduler@email.com";
		Scheduler test_scheduler2 = new Scheduler(username, password, phone, email);
		
		assertEquals("Equals assertion failed.", test_scheduler.equals(test_scheduler2), true);
	}
	
	/**
	 * This test determines whether the compareTo() method functions as intended
	 * for the Scheduler class.
	 * 
	 * 1) Tests whether the compared object is alphabetically equal.
	 * 2) Tests whether the compared object is alphabetically higher.
	 * 3) Tests whether the compared object is alphabetically lower.
	 * 
	 * All assertions in this method should return true.  If one or more
	 * assertion fails, the compareTo() method has failed to function as intended
	 * for the Scheduler class.
	 */
	@Test
	public void testCompare() {
		String password = "password";
		String phone = "123-456-7890";
		String email = "LMA@email.com";
		Scheduler test_scheduler2 = new Scheduler("aaa", password, phone, email);

		Scheduler test_scheduler3 = new Scheduler("zzz", password, phone, email);
		
		assertEquals("compareTo assertion failed.", test_scheduler.compareTo(test_scheduler) == 0, true);
		assertEquals("compareTo assertion failed.", test_scheduler.compareTo(test_scheduler2) > 0, true);
		assertEquals("compareTo assertion failed.", test_scheduler.compareTo(test_scheduler3) < 0, true);
	}

	/**
	 * Tests the Scheduler's ability to view accounts.
	 */
	@Test
	public void testViewAccount() {
		Accounts test_accounts = new Accounts();
		Volunteer test_volunteer = new Volunteer("name", "surname", "username", 
				"password", "123-456-7890", "e@mail.address", "4/1/2011");
		test_accounts.addAccount(test_volunteer);
		
		String test_string = "name,,surname,,username,,password,,123-456-7890,,e@mail.address,,4/1/2011,,false\n";
		
		assertEquals("viewAccount assertion failed.", test_scheduler.viewAccount(test_accounts, username).equals(test_string), true);
	}
	
	
	/**
	 * Tests the Scheduler's ability to set a group leader.
	 */
	@Test
	public void testSetGroupLeader() {
		Volunteer test_volunteer = new Volunteer("name", "surname", "username", 
				"password", "123-456-7890", "e@mail.address", "4/1/2011");
		test_scheduler.setGroupLeader(test_volunteer, true);
		
		assertEquals("setGroupLeader assertion failed.", test_volunteer.isLeader(), true);
	}
	
	/**
	 * Tests the Scheduler's ability to approve a job.
	 */
	@Test
	public void testApproveJob() {
		Job test_job = new Job("Test", "555-5555", "Test grounds", 0, 0, "this is a test", new Date().toString(), "time", "LMA", 9);
		test_scheduler.approveJob(test_job);
		
		assertEquals("approveJob assertion failed.", test_job.getVerified(), true);
	}
	
	/**
	 * Tests the Scheduler's ability to disable a job.
	 */
	@Test
	public void disableJob() {
		Job test_job = new Job("Test", "555-5555", "Test grounds", 0, 0, "this is a test", new Date().toString(), "time", "LMA", 9);
		test_scheduler.disableJob(test_job);
		
		assertEquals("approveJob assertion failed.", test_job.getVerified(), false);
	}
	
	
	
	
	/**
	 * Tests whether the toString() method for a Scheduler object functions
	 * as intended.
	 * 
	 * 1) Assert whether the toString() method for the Scheduler class functions as intended.
	 * 
	 * All assertions in this method should return true.  If one or more
	 * assertion fails, the toString() method has failed to function as intended
	 * for the Scheduler class.
	 */
	@Test
	public void testString() {
		String test_string = "username,,password,,123-456-7890,,scheduler@email.com\n";
		
		assertEquals("toString assertion failed.", test_scheduler.toString().equals(test_string), true);
	}
	

}
